#

| Chapter 33 Batch Editing |

## 33.10 Quick Globals from the Command Line with qsubst

Users at our office frequently have to make global changes across multiple files. For that purpose we encourage them to use sed (34.24); but sed syntax is tricky for new users (or even some experienced users!).

qsubst | As an alternative, try the qsubst program, available on our CD-ROM. qsubst is a simple query-replace program that anyone can use. For example, to change the string "Unix" into "UNIX" in the files ch01 and ch02, you can do:

>     % qsubst Unix UNIX ch01 ch02

You'll be prompted with each line to be changed, in context. That is, the line containing the string will be surrounded by both the previous and the next lines in the file. The string to be changed is underlined:

>     Unlike emacs, vi is available on
>     every \o'U_'\o'n_'\o'i_'\o'x_' system.
>     So you can
>     think of vi as the

To approve the change, press the space bar. You'll then be prompted with the next occurrence in the file. To refuse the change, press `n` to go on to the next occurrence of the string. You can also use the exclamation point (!) to approve this change and all future changes in this file, and CTRL-g to reject this change and all future changes.

You can also have qsubst replace all occurrences without prompting, using the -noask command-line option:

>     % qsubst Unix UNIX -noask ch01 ch02
>     (file: ch01)
>     (file: ch02)

Both files are edited without prompting.

qsubst is clearly not as powerful as sed. It doesn't understand regular expressions: you can only use qsubst to replace simple strings. But qsubst is clearly a useful tool for users who just want to make a simple global change without learning sed.

One word of warning about qsubst: if you interrupt qsubst midstream (e.g., using CTRL-c), your stty settings are likely to be garbled. If this happens, try the tips in article 42.4 to get your stty settings correct again.

- LM

33.9 patch: Generalized Updating of Files that Differ |  | 33.11 Quick Reference: awk